package com.fire.threadpool.interceptLongTimeThread;

import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import com.fire.threadpool.nameThreadFactory.NameThreadFactory;

/**
 * @date 2022/3/24
 * @author zwd
 * @email zwd@hhh.com
 */
public class TimeOverInterceptThreadPoolExecutorTest {
	public static void main(String[] args) {
		DelayTaskThread task1 = new DelayTaskThread1("thread1", 10000);
		DelayTaskThread task2 = new DelayTaskThread2("thread2", 100);
		DelayTaskThread task3 = new DelayTaskThread3("thread3", 100);
		TimeOverInterceptThreadPoolExecutor poolExecutor = new TimeOverInterceptThreadPoolExecutor(10, 10, 0L, TimeUnit.MICROSECONDS,
				new LinkedBlockingDeque<Runnable>(), new NameThreadFactory());
		ArrayList<DelayTaskThread> delayTaskThreads = new ArrayList<>();
		poolExecutor.execute(task1);
		poolExecutor.execute(task2);
		poolExecutor.execute(task3);
	}

	static class DelayTaskThread1 extends DelayTaskThread{

		DelayTaskThread1(String prefixName, long time) {
			super(prefixName, time);
		}

		@Override
		public void delayTask() {
			super.delayTask();
			try {
				Thread.sleep(100000);
				System.out.println("Thread " + Thread.currentThread().getName() + " over...");
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	static class DelayTaskThread2 extends DelayTaskThread{

		DelayTaskThread2(String prefixName, long time) {
			super(prefixName, time);
		}

		@Override
		public void delayTask() {
			super.delayTask();
			try {
				Thread.sleep(100);
				System.out.println("Thread " + Thread.currentThread().getName() + " over...");
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	static class DelayTaskThread3 extends DelayTaskThread{

		DelayTaskThread3(String prefixName, long time) {
			super(prefixName, time);
		}

		@Override
		public void delayTask() {
			super.delayTask();
			try {
				Thread.sleep(10);
				System.out.println("Thread " + Thread.currentThread().getName() + " over...");
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
